<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      input {
        color: #ccc;
        font-size: 14px;
      }
    </style>
  </head>
  <body>
    <input type="text" value="请输入搜索关键字" />
    <script>
      var input = document.querySelector('input')
      console.log(input)
      input.addEventListener('focus', function () {
        if (this.value === '请输入搜索关键字') {
          this.value = ''
          this.style.color = '#000'
        }
      })
      input.addEventListener('blur', function () {
        if (this.value.length === 0) {
          this.style.color = '#ccc'
          this.value = '请输入搜索关键字'
        }
      })
    </script>
  </body>
</html>
